<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="file" id="d1">
<br><hr>
<input type="button" value="click提交" onclick="submit()">
</body>
<script>
    function submit() {
        let name = document.getElementById('d1').value;
        let houzui = name.substr(name.lastIndexOf('.')+1).toLowerCase();
        if (houzui == 'png' || houzui == 'jpg' || houzui == 'gif' || houzui =='bmp'){
            alert(name+'上传成功');
        } else{
            alert('格式不符');
        }
    }
</script>
</html>